package zabbix

import (
	"encoding/json"
	"errors"
)

func EventAcknowledgeData() (string,map[string]interface{}) {
	method := "event.acknowledge"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "eventids": "20427",
        "action": 6,
        "message": "Problem resolved."
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func EventGetData() (string,map[string]interface{}) {
	method := "event.Get"
	var data map[string]interface{}
	jsonstr := []byte(`{
        "output": "extend",
        "select_acknowledges": "extend",
        "selectTags": "extend",
        "objectids": "13926",
        "sortfield": ["clock", "eventid"],
        "sortorder": "DESC"
	}`)
	json.Unmarshal(jsonstr,&data)
	return method,data
}

func EventAcknowledge(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := EventAcknowledgeData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}

func EventGet(url string,user string,password string) (interface{},*API) {
	api := LoginAndHandle(url,user,password)
	method,data := EventGetData()
	result,err:=api.ZabbixRequest(method,data)
	if err != nil {
		return nil,api
	}
	if result.Error.Code != 0 {
		err = errors.New(result.Error.Message)
		return nil,api
	}
	resultdata := result.Result
	return resultdata,api
}


